<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<%
function cf(aaTemp,iFlag)
	cf=false
	if not CheckLogin then
		call ShowError(3)
		exit function
	end if
	if iFlag="" then exit function
	if not IsArray(aaTemp) then exit function
	for i=0 to ubound(aaTemp,2)
		if aaTemp(1,i)<iFlag then exit function
	next
	cf=true
end function


if not cf(session("aaPostflag"),1) then call ShowError(2)

'获取提交查询的参数
tx_search=trim(SafeRequest("tx_search",0))
wtr=trim(SafeRequest("wtr",1))
bwtr=trim(SafeRequest("bwtr",1))
category=trim(SafeRequest("category",1))
cd_status=trim(SafeRequest("cd_status",1))
fee=trim(SafeRequest("fee",0))
passno=trim(SafeRequest("passno",0))
orderno=trim(SafeRequest("orderno",0))
boxno=trim(SafeRequest("boxno",0))
ksrq=trim(SafeRequest("ksrq",0))
if ksrq<>"" then ksrq=cdate(ksrq)
jsrq=trim(SafeRequest("jsrq",0))
if jsrq<>"" then jsrq=cdate(jsrq)
ytksrq=trim(SafeRequest("ytksrq",0))
if ytksrq<>"" then ytksrq=cdate(ytksrq)
ytjsrq=trim(SafeRequest("ytjsrq",0))
if ytjsrq<>"" then ytjsrq=cdate(ytjsrq)
cd_received=trim(SafeRequest("cd_received",0))
cd_paid=trim(SafeRequest("cd_paid",0))
post=SafeRequest("post",1)
detail=SafeRequest("detail",1)
search_count=trim(SafeRequest("search_count",1))
show_rp=trim(SafeRequest("show_rp",0))

'组合sql查询字符串
'sql="select * from cdfee where true "
sql="select "
if search_count<>0 then sql=sql&" top "&search_count
sql=sql&" * from cdfee where true "
if tx_search<>"" then
	if len(tx_search)=18 and IsNumeric(tx_search) then
		'如果是18位的报关单号，直接查询。用于扫描枪的使用，提高搜索速度
		sql=sql&" and cd_no='"&tx_search&"'"
	else
		sql=sql&" and (cd_no like '%"&tx_search&"%' or cd_company like '%"&tx_search&"%' or cd_voyage like '%"&tx_search&"%' or cd_lading like '%"&tx_search&"%' or cd_verify like '%"&tx_search&"%' or cd_passno like '%"&tx_search&"%' or cd_orderno like '%"&tx_search&"%' or cd_boxno like '%"&tx_search&"%' or cd_memo like '%"&tx_search&"%')"
	end if
end if
if wtr<>0 then sql=sql&" and wtr="&wtr
if bwtr<>0 then sql=sql&" and bwtr="&bwtr
if category<>0 then sql=sql&" and category="&category
if cd_status<>0 then sql=sql&" and cd_status="&cd_status
if ksrq<>"" and jsrq<>"" then	sql=sql&" and (cd_date>=#"&ksrq&"# and cd_date<=#"&jsrq&"#)"
if ytksrq<>"" and ytjsrq<>"" then	sql=sql&" and (cd_statusdate>=#"&ytksrq&"# and cd_statusdate<=#"&ytjsrq&"#)"
if cd_received<>"" then sql=sql&" and cd_received="&cd_received
if cd_paid<>"" then sql=sql&" and cd_paid="&cd_paid
if post=0 then
'如果不选择要查询的岗位，则查询该用户所有的有查询权限的岗位
	sSearchPost=""
	for i=0 to ubound(session("aaPostFlag"),2)
		if session("aaPostFlag")(1,i)>=1 and session("aaPostFlag")(0,i)<>0 and session("aaPostFlag")(0,i)<>5 then
			sSearchPost=sSearchPost&session("aaPostFlag")(0,i)&","
		end if
	next
	if len(sSearchPost)>0 then
		sSearchPost=left(sSearchPost,len(sSearchPost)-1)
		sql=sql&" and cd_post in ("&sSearchPost&")"
	else
		sql=sql&" and cd_post=-1"
	end if
else
'如果选择了查询岗位，则只查询该岗位
	sql=sql&" and cd_post="&post
end if
'查询详细费用的类别，判断是否有该类别的费用产生，返回cd
if detail<>0 then
	set rs_detail=Server.CreateObject("ADODB.Recordset")
	sql_detail="select DISTINCT cd from feedetail where feecategory.id="&detail
	rs_detail.open sql_detail,conn,1,1
	if not rs_detail.eof then
		'如果找到该类别的详细费用，就组合字段
		detail_querystring=rs_detail.getstring(,,,",")
	else
		'如果没找到该类别的详细费用，就用0来查询
		detail_querystring="0"
	end if
	rs_detail.close
	set rs_detail=nothing
	sql=sql&" and id in ("&detail_querystring&")"
end if

if fee<>"" then
	if fee then	sql=sql&" and not isnull(cd)" else sql=sql&" and isnull(cd)"
end if
if passno<>"" then
	if passno then sql=sql&" and cd_passno<>''" else sql=sql&" and cd_passno=''"
end if
if orderno<>"" then
	if orderno then sql=sql&" and cd_orderno<>''" else sql=sql&" and cd_orderno=''"
end if
if boxno<>"" then
	if boxno then sql=sql&" and cd_boxno<>''" else sql=sql&" and cd_boxno=''"
end if
sql=sql&" order by cd_update desc"
'response.write sql
'response.end
'执行数据查询
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
If rs.eof Then
	response.write("没有检索到数据!")
	response.end
else
	sql_sum="select sum(cd_receive) as sum_cd_receive,sum(cd_pay) as sum_cd_pay,sum(cd_actreceive) as sum_cd_actreceive,sum(cd_actpay) as sum_cd_actpay,sum(total_receive) as sum_total_receive,sum(total_pay) as sum_total_pay from("&sql&")"
	set rs_sum = Server.CreateObject("ADODB.Recordset")
	rs_sum.open sql_sum,conn,1,1
	sum_cd_receive=rs_sum("sum_cd_receive")
	sum_cd_pay=rs_sum("sum_cd_pay")
	sum_cd_actreceive=rs_sum("sum_cd_actreceive")
	sum_cd_actpay=rs_sum("sum_cd_actpay")
	sum_total_receive=rs_sum("sum_total_receive")
	sum_total_pay=rs_sum("sum_total_pay")
	rs_sum.close
	set rs_sum=nothing
End if

'分页控制
If saferequest("page",0)<>"" Then	page=clng(saferequest("page",0)) Else	page=1
pc=saferequest("pc",1)
If pc="" Then pc=25
rs.pagesize=pc
pagesize=rs.pagesize
pagecount=rs.pagecount
'page=clng(request.QueryString("page"))
if Not IsEmpty(page) then '如果page_num已经初始化...
	if Not IsNumeric(page) then '判断page_num值是否为数字
		page=1
	else
		page = clng(page) '接收page_num并化为数字型赋给page_num变量
	end if
	if page > pagecount then '如果接收的页数大于总页数
		rs.AbsolutePage = pagecount '设置当前显示页等于最后页
	elseif page <= 0 then '如果page小于等于0
		page=1
		rs.AbsolutePage = page '设置当前显示页等于第一页
	else
		rs.AbsolutePage = page '如果大于零,显示当前页等于接收的页数
	end if
	page = rs.AbsolutePage
end if
%>
<table class="full">
	<thead>
		<tr>
			<th scope="col" rowspan="2"><input type="checkbox" id="checkall"></th>
			<th scope="col" rowspan="2">ID</th>
			<%if wtr=0 then%>
			<th scope="col" rowspan="2">委托人</th>
			<%end if%>
			<%if bwtr=0 then%>
			<th scope="col" rowspan="2">被委托人</th>
			<%end if%>
			<%if category=0 then%>
			<th scope="col" rowspan="2">类型</th>
			<%end if%>
			<th scope="col" rowspan="2">报关单号</th>
			<th scope="col" rowspan="2">申报日期</th>
			<th scope="col" rowspan="2">企业名称</th>
			<th scope="col" rowspan="2">船名/航次</th>
			<th scope="col" rowspan="2">提单号</th>
			<th scope="col" rowspan="2">核销单号</th>
			<%if passno="true" then%>
			<th scope="col" rowspan="2">通关单号</th>
			<%end if%>
			<%if orderno="true" then%>
			<th scope="col" rowspan="2">订单号</th>
			<%end if%>
			<%if boxno="true" then%>
			<th scope="col" rowspan="2">箱号</th>
			<%end if%>
			<th scope="col" colspan="<%if show_rp="" then response.write("2") else response.write("1")%>">报关费</th>
			<th scope="col" colspan="<%if show_rp="" then response.write("2") else response.write("1")%>">合计</th>
			<th scope="col" colspan="<%if show_rp="" then response.write("2") else response.write("1")%>">实际</th>
			<%if post=0 then%>
			<th scope="col" rowspan="2">岗位</th>
			<%end if%>
			<th scope="col" rowspan="2">备注</th>
		</tr>
		<tr>
			<%if show_rp<>"false" then%>
			<th scope="col">应收</th>
			<%end if%>
			<%if show_rp<>"true" then%>
			<th scope="col">应付</th>
			<%end if%>
			<%if show_rp<>"false" then%>
			<th scope="col">应收</th>
			<%end if%>
			<%if show_rp<>"true" then%>
			<th scope="col">应付</th>
			<%end if%>
			<%if show_rp<>"false" then%>
			<th scope="col">已收</th>
			<%end if%>
			<%if show_rp<>"true" then%>
			<th scope="col">已付</th>
			<%end if%>
		</tr>
	</thead>
	<tbody>
<%
	For i=1 To pagesize
		If rs.eof Then Exit for
%>
		<tr>
			<th class="sub" scope="row"><input type="checkbox" name="checkid" class="checkid" value="<%=rs("id")&"|"&rs("cd_received")&"|"&rs("total_receive")&"|"&rs("cd_paid")&"|"&rs("total_pay")%>" /></th>
			<th class="sub" scope="row"><a href="process.asp?id=<%=rs("id")%>" target="_blank"><%=rs.AbsolutePosition%></a></th>
			<%if wtr=0 then%>
			<td><%=rs("wtr_name")%></td>
			<%end if%>
			<%if bwtr=0 then%>
			<td><%=rs("bwtr_name")%></td>
			<%end if%>
			<%if category=0 then%>
			<td><%=rs("category_name")%></td>
			<%end if%>
			<td title="<%=rs("cd_no")%>"><%=right(rs("cd_no"),9)%></td>
			<td><%=rs("cd_date")%></td>
			<td><%=rs("cd_company")%></td>
			<td><%=rs("cd_voyage")%></td>
			<td><%=rs("cd_lading")%></td>
			<td><%=rs("cd_verify")%></td>
			<%if passno="true" then%>
			<td><%=rs("cd_passno")%></td>
			<%end if%>
			<%if orderno="true" then%>
			<td><%=rs("cd_orderno")%></td>
			<%end if%>
			<%if boxno="true" then%>
			<td><%=rs("cd_boxno")%></td>
			<%end if%>
			<%if show_rp<>"false" then%>
			<td align="center"><%=rs("cd_receive")%></td>
			<%end if%>
			<%if show_rp<>"true" then%>
			<td align="center"><%=rs("cd_pay")%></td>
			<%end if%>
			<%if show_rp<>"false" then%>
			<td align="center" <%if rs("cd_received") then response.write("class='highlight'")%>><%if rs("total_receive")<>rs("cd_receive") then response.write("<strong>"&rs("total_receive")&"</strong>") else response.write(rs("total_receive"))%></td>
			<%end if%>
			<%if show_rp<>"true" then%>
			<td align="center" <%if rs("cd_paid") then response.write("class='highlight'")%>><%if rs("total_pay")<>rs("cd_pay") then response.write("<strong>"&rs("total_pay")&"</strong>") else response.write(rs("total_pay"))%></td>
			<%end if%>
			<%if show_rp<>"false" then%>
			<td align="center"><%=rs("cd_actreceive")%></td>
			<%end if%>
			<%if show_rp<>"true" then%>
			<td align="center"><%=rs("cd_actpay")%></td>
			<%end if%>
			<%if post=0 then%>
			<td><%=GetPostString(rs("cd_post"))%></td>
			<%end if%>
			<td><%=rs("cd_memo")%></td>
		</tr>
<%
	rs.movenext()
next
If page=pagecount Then
%>
		<tr>
			<th class="sub" scope="row">合计</th>
			<th class="sub" scope="row"></th>
			<%if wtr=0 then%>
			<th class="sub" scope="row"></th>
			<%end if%>
			<%if bwtr=0 then%>
			<th class="sub" scope="row"></th>
			<%end if%>
			<%if category=0 then%>
			<th class="sub" scope="row"></th>
			<%end if%>
			<th class="sub" scope="row"></th>
			<th class="sub" scope="row"></th>
			<th class="sub" scope="row"></th>
			<th class="sub" scope="row"></th>
			<th class="sub" scope="row"></th>
			<th class="sub" scope="row"></th>
			<%if passno="true" then%>
			<th class="sub" scope="row"></th>
			<%end if%>
			<%if orderno="true" then%>
			<th class="sub" scope="row"></th>
			<%end if%>
			<%if boxno="true" then%>
			<th class="sub" scope="row"></th>
			<%end if%>
			<%if show_rp<>"false" then%>
			<th class="sub" scope="row"><%=sum_cd_receive%></th>
			<%end if%>
			<%if show_rp<>"true" then%>
			<th class="sub" scope="row"><%=sum_cd_pay%></th>
			<%end if%>
			<%if show_rp<>"false" then%>
			<th class="sub" scope="row"><%=sum_total_receive%></th>
			<%end if%>
			<%if show_rp<>"true" then%>
			<th class="sub" scope="row"><%=sum_total_pay%></th>
			<%end if%>
			<%if show_rp<>"false" then%>
			<th class="sub" scope="row"><%=sum_cd_actreceive%></th>
			<%end if%>
			<%if show_rp<>"true" then%>
			<th class="sub" scope="row"><%=sum_cd_actpay%></th>
			<%end if%>
			<%if post=0 then%>
			<th class="sub" scope="row"></th>
			<%end if%>
			<th class="sub" scope="row"></th>
		</tr>
<%end if%>
	</tbody>
</table>
<div>
	<span id="pagebar">
		共查询到&nbsp;<%=rs.RecordCount%>&nbsp;条记录&nbsp;
	<%if CheckFlag(session("aaPostflag"),2) then%>
		<input id="print_search" class="bt_button" type="button" value="打印查询结果" />&nbsp;&nbsp;
	<%end if%>
		<%	If page>1 Then	%>
			[<a href="#" id="1">首页</a>]
			[<a href="#" id="<%=page-1%>">上一页</a>]
		<%
				End If
				If Not (page>=pagecount Or pagecount=0) Then
		%>
			[<a href="#" id="<%=page+1%>">下一页</a>]
			[<a href="#" id="<%=pagecount%>">尾页</a>]
		<%	End If %>
			第 <%=page%> 页 / 共 <%=pagecount%> 页
			转到<input id="page_val" type="text" size="2" maxlength="<%=Int(Log(pagecount))+1%>" value="<%=page%>" />页
			<input id="page_go" class="bt_button" type="button" value="Go" />
	</span>
  <span>
	<%if post=4 and CheckPostFlag(session("aaPostflag"),4,4) then%>
		<input class="bt_button bt_act" type="button" value="已收" />
		<input class="bt_button bt_act" type="button" value="已付" />
	<%end if%>
	</span>
</div>
<%
rs.close
Set rs=nothing
%>

<!--#include file="lib/connclose.asp"-->

